{echo:JS::import('dialog?skin=brief');}
{echo:JS::import('dialogtools');}
{echo:JS::import('form');}
{echo:JS::import('date');}
<style type="text/css">
    #table_option td{
        width: 8px;
        height: 8px;
        background: #ddd;
        border:1px #999 solid;
        cursor: pointer;
    }
</style>

<h1 class="page_title">
	{if:empty($my_ad_obj)}添加{else:}编辑{/if}首页广告
</h1>

<form action="{url:/content/my_ad_save}" method="post" id="my_ad_form">
	
	<div id="obj_form" class="form2">
	
		<dl class="lineD">
	    <dt>广告名称：</dt>
	    <dd>
	    	<input type="text" id="name" name="name" value="{$my_ad_obj['name']}" class="big" >
	    </dd>
	    </dl>
	    
	    <dl class="lineD">
	    <dt>顺序：</dt>
	    <dd>
	    	<input type="text" id="ad_order" name="ad_order" value="{$obj['order']|'0'}" class="big" >
	    </dd>
	    </dl>
	    
		<dl class="lineD">
	    <dt>类别：</dt>
	    <dd>
	    	<select name="sel_category" id="sel_category" onchange="change_goods()" style="width:368px;">
	    		<option value="0">--请选择类别--</option>
	    	{query:name=goods_category where=parent_id eq 0}
	    		<option value="{$item[id]}">{$item['name']}</option>
	    	{/query}
	    	</select>
	    </dd>
	    </dl>
	    
	    <dl class="lineD">
	    <dt>相关商品：</dt>
	    <dd>
	    	<select name="sel_goods" id="sel_goods" style="width:368px;">
	    		<!-- 
	    		<option value="0">--请选择商品--</option>
	    		-->
	    	</select>&nbsp;
	    	<input type="button" value="添加" id="btn_add"/>
	    </dd>
	    </dl>
	    
	    <dl class="lineD">
	    <dt>目标对象：</dt>
	    <dd>
	    	<select name="sel_mubiao" id="sel_mubiao" multiple='multiple' style="width:368px;height:300px;">
	    	</select>&nbsp;
	    	<ul style="position:absolute;top:100px;left:523px;">
	    		<li><input type="button" value="移除" id="btn_remove"/></li>
	    		<li><input type="button" value="上移" id="btn_pre"/></li>
	    		<li><input type="button" value="下移" id="btn_next"/></li>
	    	</ul>
	    </dd>
	    </dl>
	    
	    <div style="text-align:center">
	    	<input type="hidden" name="id" value="{$obj['id']}"/>
	    	<input id="btn_submit" type="button" value="提交" class="button">&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="重置" class="button">
	    </div>
	</div>

</form>


<script type="text/javascript">

$(function(){
	
	$("#sel_category").change(function(){
		var category_id = $("#sel_category").val();
		$("#sel_goods option:gt(0)").remove();
		$.post("{url:/app/getGoodsListByClassifyId}",{category_id :category_id },function(data){
			
			
			var str = '', i;
			if(data.length<1)
			{
				//$("#sel_goods").html("<option value='0'>--请选择商品--</option>");
				$("#sel_goods").html("");
			}
			else
			{
				$("#sel_goods").html("");
				for(i=0,c=data.length; i<c; i++)
				{
					str += "<option value='"+data[i]['id']+"'>"+data[i]['name']+" -- "+data[i]['sell_price']+"元</option>";
				}
				$("#sel_goods").append( str );
			}
			
			
		},'json');
	});
	
	
	//添加元素
	$("#btn_add").click(function(){
		var selected_item = $("#sel_goods").find("option:selected");
		if(selected_item.length > 0)
		{
			var v = selected_item.val();
			var is_flag = true;
			$("#sel_mubiao").find("option").each(function(){
				if($(this).val() == v)
				{
					is_flag = false;
					alert('该商品已存在于目标对象中，请不要重复操作');
					return false;;
				}
			});
			if( is_flag )
			{
				selected_item.clone().appendTo("#sel_mubiao");	
			}
		}
	});
	
	//向上移动元素
	$("#btn_remove").click(function(){
		$("#sel_mubiao").find("option:selected").remove();
	});
	
	//向上移动元素
	$("#btn_pre").click(function(){
		//获取选中项
		var selected_item = $("#sel_mubiao option:selected");
		//插入到选中项前一个option元素之前
		selected_item.insertBefore(selected_item.prev('option'))
	});
	
	//向下移动元素
	$("#btn_next").click(function(){
		//获取选中项
		var selected_item = $("#sel_mubiao option:selected");
		//插入到选中项后一个option元素之后
		selected_item.insertAfter(selected_item.next('option'))
	});
	
	
	$("#btn_submit").click(function(){
		
	});
});

/*
function check()
{
	var sel_category = $("#sel_category").val();
	var sel_seller = $("#sel_goods").val();
	if(sel_category == 0)
	{
		alert('请选择类别');
		return false;
	}
	
	if(sel_seller == 0)
	{
		alert('请选择商品');
		return false;
	}
}
*/






$("#table_option td:eq({$contents[0]['position']})").css("background","#000");
</script>